﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using System.Collections;
using System.IO;

namespace NHTrace
{
  public class DebugProcessTracker
  {
    private IList<string> _processesBeingDebugged = new List<string>();

    public bool AreProcessesBeingDebugged
    { 
      get 
      {
        return _processesBeingDebugged.Count > 0;
      } 
    }

    public bool ProcessIsBeingDebugged(string processName)
    {
      return _processesBeingDebugged.Count(s => s.Equals(processName, StringComparison.OrdinalIgnoreCase)) > 0;
    }

    public void UpdateProcessesBeingDebugged(Processes processes)
    {
      _processesBeingDebugged.Clear();

      IEnumerator enumerator = processes.GetEnumerator();
      while (enumerator.MoveNext())
      {
        var procName = Path.GetFileName(((EnvDTE.Process)enumerator.Current).Name);
        _processesBeingDebugged.Add(procName);
      }
    }
  }
}
